//
//  RetentionController.swift
//  rdb-led-banner
//
//  Created by GJC on 2025/4/21.
//

import UIKit
import SnapKit

class RdbRetentionController: BaseViewController {

    var closeAction: (() -> Void)?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addSubview(continueButton)
        self.continueButton.snp.makeConstraints{
            $0.bottom.equalTo(-UIDevice.safeAreaBottom() - 33)
            $0.centerX.equalToSuperview()
            $0.size.equalTo(CGSize(width: UIDevice.contentWidth(), height: 54))
        }
        self.showCloseButton()
    }
    
    private lazy var continueButton: UIButton = RdbViewUtils.shared.createCircleButton(
        fontSize: 22.0,
        title: "CONTINUE FOR FREE",
        cornerRadius: 27,
        backgroundColor: "#5210E1",
        target: self,
        action: #selector(continueButtonAction)
    )
    
    @objc func continueButtonAction(){
        /// 订阅
    }
    
    func showCloseButton(){
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.0){
            self.navigationItem.rightBarButtonItem = self.closeButtonItem
            if #available(iOS 16.0, *) {
                self.closeButtonItem.isHidden = false
            }
        }
    }

    
    private lazy var closeButtonItem: UIBarButtonItem = {
        let closeButtonItem = UIBarButtonItem(image: UIImage(named: "guide_close")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(closeButtonAction))
        return closeButtonItem
    }()
    
    @objc func closeButtonAction(){
        self.closeAction?()
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
